package com.android.equipment.dao.operate;

import com.android.equipment.ObjectBox;
import com.android.equipment.dao.WorkEvidence;
import com.android.equipment.dao.WorkEvidence_;

import java.util.List;

import io.objectbox.Box;
import io.objectbox.query.Query;

public class DaoWorkEvidence {
    static Box<WorkEvidence> workEvidenceBox;
    private static DaoWorkEvidence instance;

    private DaoWorkEvidence() {
    }

    public static DaoWorkEvidence getInstance() {
        if (instance == null) {
            instance = new DaoWorkEvidence();
            workEvidenceBox = ObjectBox.get().boxFor(WorkEvidence.class);
        }
        return instance;
    }

    public void addWorkEvidence(WorkEvidence workEvidence) {
        workEvidenceBox.put(workEvidence);
    }

    public void delWorkEvidence(WorkEvidence workEvidence) {
        workEvidenceBox.remove(workEvidence);
    }

    public WorkEvidence getWorkEvidence(long id) {
        return workEvidenceBox.get(id);
    }

    public List<WorkEvidence> getWorkEvidenceData(long workId) {
        Query<WorkEvidence> query = workEvidenceBox.query().equal(WorkEvidence_.workId, workId).build();
        List<WorkEvidence> workEvidences = query.find();
        query.close();
        return workEvidences;
    }

    public void updateWorkEvidence(WorkEvidence workEvidence) {
        workEvidenceBox.put(workEvidence);
    }
}
